﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiExportPaintFilesForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Drawing;
using System.IO;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

public class CUiExportPaintFilesForm : TxForm
{
  private SaveFileDialog m_xmlSaveFileDialog;
  private TextBox m_saveSimFileAsTextBox;
  private Label label1;
  private Label label2;
  private Button m_saveSimFileAsButton;
  private TxNumericEditBoxCtrl m_timeIntervalEditBox;
  private Label label3;
  private TxObjEditBoxCtrl m_operationEditBox;
  private Button m_closeButton;
  private SaveFileDialog m_jtSaveFileDialog;
  private bool m_lineSimulationMode;
  private const string COMMAND_NAME = "GeneratePaintFiles";
  private const string SAVE_JT_FILE_PATH = "SaveJtFilePath";
  private const string SAVE_SIM_XML_FILE_PATH = "SaveSimXmlFilePath";
  private const string SIM_TIME_INTERVAL_PATH = "TimeInterval";
  private ResourceManager m_resourceManager;
  private TextBox m_saveJTFileAsTextBox;
  private Label label6;
  private Button m_saveJtAsButton;
  private CheckBox m_createJtCheckBox;
  private CheckBox m_createSimFileCheckBox;
  private TxObjGridCtrl m_partsTxObjGridCtrl;
  private Button m_createButton;
  private CApExportPaintFilesApp m_app;
  private bool m_externalSimulationRunning;
  private Label label4;
  private RadioButton m_independentRadioButton;
  private RadioButton m_lineOpContextRadioButton;
  private Label m_simulateLabel;
  private bool m_internalSimulationRunning;

  protected virtual void Dispose(bool disposing) => base.Dispose(disposing);

  private void InitializeComponent()
  {
    this.m_operationEditBox = new TxObjEditBoxCtrl();
    this.m_xmlSaveFileDialog = new SaveFileDialog();
    this.m_saveSimFileAsTextBox = new TextBox();
    this.label1 = new Label();
    this.label2 = new Label();
    this.m_saveSimFileAsButton = new Button();
    this.m_timeIntervalEditBox = new TxNumericEditBoxCtrl();
    this.label3 = new Label();
    this.m_closeButton = new Button();
    this.m_jtSaveFileDialog = new SaveFileDialog();
    this.m_saveJTFileAsTextBox = new TextBox();
    this.label6 = new Label();
    this.m_saveJtAsButton = new Button();
    this.m_createJtCheckBox = new CheckBox();
    this.m_createSimFileCheckBox = new CheckBox();
    this.m_partsTxObjGridCtrl = new TxObjGridCtrl();
    this.m_createButton = new Button();
    this.label4 = new Label();
    this.m_independentRadioButton = new RadioButton();
    this.m_lineOpContextRadioButton = new RadioButton();
    this.m_simulateLabel = new Label();
    ((Control) this).SuspendLayout();
    this.m_operationEditBox.ListenToPick = false;
    ((Control) this.m_operationEditBox).Location = new Point(111, 192 /*0xC0*/);
    ((Control) this.m_operationEditBox).Name = "m_operationEditBox";
    this.m_operationEditBox.Object = (ITxObject) null;
    this.m_operationEditBox.PickLevel = (TxPickLevel) 1;
    this.m_operationEditBox.PickOnly = false;
    this.m_operationEditBox.ReadOnly = false;
    ((Control) this.m_operationEditBox).Size = new Size(202, 20);
    ((Control) this.m_operationEditBox).TabIndex = 0;
    this.m_operationEditBox.ValidatorType = (TxValidatorType) 10;
    this.m_operationEditBox.TypeValid += new EventHandler(this.m_operationEditBox_TypeValid);
    ((Control) this.m_operationEditBox).Leave += new EventHandler(this.m_operationEditBox_Leave);
    this.m_operationEditBox.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.m_operationEditBox_Picked);
    ((Control) this.m_operationEditBox).Enter += new EventHandler(this.m_operationEditBox_Enter);
    this.m_saveSimFileAsTextBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
    this.m_saveSimFileAsTextBox.Location = new Point(111, 301);
    this.m_saveSimFileAsTextBox.Name = "m_saveSimFileAsTextBox";
    this.m_saveSimFileAsTextBox.Size = new Size(202, 20);
    this.m_saveSimFileAsTextBox.TabIndex = 1;
    this.m_saveSimFileAsTextBox.TextChanged += new EventHandler(this.m_saveSimFileAsTextBox_TextChanged);
    this.label1.AutoSize = true;
    this.label1.Location = new Point(27, 196);
    this.label1.Name = "label1";
    this.label1.Size = new Size(56, 13);
    this.label1.TabIndex = 2;
    this.label1.Text = "Operation:";
    this.label2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
    this.label2.AutoSize = true;
    this.label2.Location = new Point(27, 305);
    this.label2.Name = "label2";
    this.label2.Size = new Size(82, 13);
    this.label2.TabIndex = 3;
    this.label2.Text = "Target XML file:";
    this.m_saveSimFileAsButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
    this.m_saveSimFileAsButton.Location = new Point(318, 301);
    this.m_saveSimFileAsButton.Name = "m_saveSimFileAsButton";
    this.m_saveSimFileAsButton.Size = new Size(22, 20);
    this.m_saveSimFileAsButton.TabIndex = 4;
    this.m_saveSimFileAsButton.Text = "...";
    this.m_saveSimFileAsButton.UseVisualStyleBackColor = true;
    this.m_saveSimFileAsButton.Click += new EventHandler(this.m_saveSimFileAsButton_Click);
    ((Control) this.m_timeIntervalEditBox).Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
    this.m_timeIntervalEditBox.BorderStyle = BorderStyle.Fixed3D;
    ((Control) this.m_timeIntervalEditBox).Location = new Point(111, 274);
    this.m_timeIntervalEditBox.LowerBound = 0.01;
    ((Control) this.m_timeIntervalEditBox).Name = "m_timeIntervalEditBox";
    this.m_timeIntervalEditBox.ReadOnly = false;
    ((Control) this.m_timeIntervalEditBox).Size = new Size(70, 21);
    this.m_timeIntervalEditBox.StepSize = 0.01;
    ((Control) this.m_timeIntervalEditBox).TabIndex = 6;
    this.m_timeIntervalEditBox.TextAlign = HorizontalAlignment.Left;
    this.m_timeIntervalEditBox.ThousandsSeparator = false;
    this.m_timeIntervalEditBox.UpperBound = 1.0;
    this.m_timeIntervalEditBox.Value = 0.01;
    this.m_timeIntervalEditBox.ValueType = (TxNumericEditValueType) 0;
    this.label3.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
    this.label3.AutoSize = true;
    this.label3.Location = new Point(27, 278);
    this.label3.Name = "label3";
    this.label3.Size = new Size(70, 13);
    this.label3.TabIndex = 7;
    this.label3.Text = "Time interval:";
    this.m_closeButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
    this.m_closeButton.Location = new Point(275, 330);
    this.m_closeButton.Name = "m_closeButton";
    this.m_closeButton.Size = new Size(65, 23);
    this.m_closeButton.TabIndex = 8;
    this.m_closeButton.Text = "Close";
    this.m_closeButton.UseVisualStyleBackColor = true;
    this.m_closeButton.Click += new EventHandler(this.button3_Click);
    this.m_saveJTFileAsTextBox.Location = new Point(111, 134);
    this.m_saveJTFileAsTextBox.Name = "m_saveJTFileAsTextBox";
    this.m_saveJTFileAsTextBox.Size = new Size(202, 20);
    this.m_saveJTFileAsTextBox.TabIndex = 5;
    this.m_saveJTFileAsTextBox.TextChanged += new EventHandler(this.m_saveJTFileAsTextBox_TextChanged);
    this.label6.AutoSize = true;
    this.label6.Location = new Point(27, 138);
    this.label6.Name = "label6";
    this.label6.Size = new Size(72, 13);
    this.label6.TabIndex = 6;
    this.label6.Text = "Target JT file:";
    this.m_saveJtAsButton.Location = new Point(318, 134);
    this.m_saveJtAsButton.Name = "m_saveJtAsButton";
    this.m_saveJtAsButton.Size = new Size(22, 20);
    this.m_saveJtAsButton.TabIndex = 7;
    this.m_saveJtAsButton.Text = "...";
    this.m_saveJtAsButton.UseVisualStyleBackColor = true;
    this.m_saveJtAsButton.Click += new EventHandler(this.m_saveJtAsButton_Click);
    this.m_createJtCheckBox.AutoSize = true;
    this.m_createJtCheckBox.Location = new Point(12, 12);
    this.m_createJtCheckBox.Name = "m_createJtCheckBox";
    this.m_createJtCheckBox.Size = new Size(88, 17);
    this.m_createJtCheckBox.TabIndex = 10;
    this.m_createJtCheckBox.Text = "Create JT file";
    this.m_createJtCheckBox.UseVisualStyleBackColor = true;
    this.m_createJtCheckBox.CheckedChanged += new EventHandler(this.m_createJtCheckBox_CheckedChanged);
    this.m_createSimFileCheckBox.AutoSize = true;
    this.m_createSimFileCheckBox.Location = new Point(12, 169);
    this.m_createSimFileCheckBox.Name = "m_createSimFileCheckBox";
    this.m_createSimFileCheckBox.Size = new Size(122, 17);
    this.m_createSimFileCheckBox.TabIndex = 11;
    this.m_createSimFileCheckBox.Text = "Create simulation file";
    this.m_createSimFileCheckBox.UseVisualStyleBackColor = true;
    this.m_createSimFileCheckBox.CheckedChanged += new EventHandler(this.m_createSimFileCheckBox_CheckedChanged);
    ((UserControl) this.m_partsTxObjGridCtrl).BorderStyle = BorderStyle.FixedSingle;
    this.m_partsTxObjGridCtrl.ChangeGeneralSelection = false;
    this.m_partsTxObjGridCtrl.CurrentRow = -1;
    this.m_partsTxObjGridCtrl.EnableMultipleSelection = true;
    this.m_partsTxObjGridCtrl.EnableRecurringObjects = false;
    this.m_partsTxObjGridCtrl.ListenToPick = true;
    ((Control) this.m_partsTxObjGridCtrl).Location = new Point(30, 35);
    ((Control) this.m_partsTxObjGridCtrl).Name = "m_partsTxObjGridCtrl";
    this.m_partsTxObjGridCtrl.PickLevel = (TxPickLevel) 1;
    ((Control) this.m_partsTxObjGridCtrl).Size = new Size(310, 91);
    ((Control) this.m_partsTxObjGridCtrl).TabIndex = 12;
    this.m_partsTxObjGridCtrl.ValidatorType = (TxValidatorType) 3;
    this.m_partsTxObjGridCtrl.Picked += new TxObjGridCtrl_PickedEventHandler(this.m_partsTxObjGridCtrl_Picked);
    this.m_partsTxObjGridCtrl.RowDeleted += new TxObjGridCtrl_RowDeletedEventHandler(this.m_partsTxObjGridCtrl_RowDeleted);
    this.m_createButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
    this.m_createButton.Location = new Point(204, 330);
    this.m_createButton.Name = "m_createButton";
    this.m_createButton.Size = new Size(65, 23);
    this.m_createButton.TabIndex = 13;
    this.m_createButton.Text = "Create";
    this.m_createButton.UseVisualStyleBackColor = true;
    this.m_createButton.Click += new EventHandler(this.m_okButton_Click);
    this.label4.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
    this.label4.AutoSize = true;
    this.label4.Location = new Point(187, 278);
    this.label4.Name = "label4";
    this.label4.Size = new Size(30, 13);
    this.label4.TabIndex = 15;
    this.label4.Text = "(sec)";
    this.m_independentRadioButton.AutoSize = true;
    this.m_independentRadioButton.Location = new Point(111, 222);
    this.m_independentRadioButton.Name = "m_independentRadioButton";
    this.m_independentRadioButton.Size = new Size(92, 17);
    this.m_independentRadioButton.TabIndex = 16 /*0x10*/;
    this.m_independentRadioButton.TabStop = true;
    this.m_independentRadioButton.Text = "Independently";
    this.m_independentRadioButton.UseVisualStyleBackColor = true;
    this.m_lineOpContextRadioButton.AutoSize = true;
    this.m_lineOpContextRadioButton.Location = new Point(111, 245);
    this.m_lineOpContextRadioButton.Name = "m_lineOpContextRadioButton";
    this.m_lineOpContextRadioButton.Size = new Size(186, 17);
    this.m_lineOpContextRadioButton.TabIndex = 17;
    this.m_lineOpContextRadioButton.TabStop = true;
    this.m_lineOpContextRadioButton.Text = "In the context of the line operation";
    this.m_lineOpContextRadioButton.UseVisualStyleBackColor = true;
    this.m_simulateLabel.AutoSize = true;
    this.m_simulateLabel.Location = new Point(27, 222);
    this.m_simulateLabel.Name = "m_simulateLabel";
    this.m_simulateLabel.Size = new Size(50, 13);
    this.m_simulateLabel.TabIndex = 18;
    this.m_simulateLabel.Text = "Simulate:";
    ((Form) this).ClientSize = new Size(351, 365);
    ((Control) this).Controls.Add((Control) this.m_simulateLabel);
    ((Control) this).Controls.Add((Control) this.m_lineOpContextRadioButton);
    ((Control) this).Controls.Add((Control) this.m_independentRadioButton);
    ((Control) this).Controls.Add((Control) this.label4);
    ((Control) this).Controls.Add((Control) this.m_createButton);
    ((Control) this).Controls.Add((Control) this.m_partsTxObjGridCtrl);
    ((Control) this).Controls.Add((Control) this.m_createSimFileCheckBox);
    ((Control) this).Controls.Add((Control) this.m_createJtCheckBox);
    ((Control) this).Controls.Add((Control) this.label3);
    ((Control) this).Controls.Add((Control) this.m_timeIntervalEditBox);
    ((Control) this).Controls.Add((Control) this.m_saveJtAsButton);
    ((Control) this).Controls.Add((Control) this.label6);
    ((Control) this).Controls.Add((Control) this.m_closeButton);
    ((Control) this).Controls.Add((Control) this.m_saveJTFileAsTextBox);
    ((Control) this).Controls.Add((Control) this.m_saveSimFileAsButton);
    ((Control) this).Controls.Add((Control) this.label2);
    ((Control) this).Controls.Add((Control) this.m_operationEditBox);
    ((Control) this).Controls.Add((Control) this.label1);
    ((Control) this).Controls.Add((Control) this.m_saveSimFileAsTextBox);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiExportPaintFilesForm);
    ((Form) this).ShowIcon = false;
    ((Control) this).Text = "Export Files for Paint Simulation";
    ((Form) this).FormClosing += new FormClosingEventHandler(this.CUiPaintSimulatorForm_FormClosing);
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }

  public CUiExportPaintFilesForm()
  {
    this.InitializeComponent();
    this.m_timeIntervalEditBox.Value = TxApplication.Options.Simulation.TimeInterval;
    this.LoadStorageData();
    this.EnableButtons();
    this.m_operationEditBox.SetValidator((ITxValidator) new TxTypeFilterValidator((ITxTypeFilter) new TxTypeFilter(typeof (ITxRoboticOrderedCompoundOperation))));
    this.m_resourceManager = new ResourceManager("DnProcessSimulateCommands.ExportPaintFiles.StringTable", ((object) this).GetType().Assembly);
    this.m_app = new CApExportPaintFilesApp();
    this.m_lineSimulationMode = TxEngineeringDataInternal.GlobalGetPartsMode() == 2;
    this.SetFormMode();
    this.EnableCreateJtSection(false);
    this.EnableCreateSimFileSection(false);
    this.SetPickProviders();
    this.InitObjectsGrid();
  }

  private void SetFormMode()
  {
    if (this.m_lineSimulationMode)
    {
      ((Control) this).Height = 390;
      this.m_simulateLabel.Show();
      this.m_independentRadioButton.Show();
      this.m_lineOpContextRadioButton.Show();
      this.m_lineOpContextRadioButton.Checked = true;
    }
    else
    {
      ((Control) this).Height = 334;
      this.m_simulateLabel.Hide();
      this.m_independentRadioButton.Hide();
      this.m_lineOpContextRadioButton.Hide();
    }
  }

  private void InitObjectsGrid()
  {
    string str = this.m_resourceManager.GetString("OBJECT_LIST_TITLE");
    TxGridColumnData txGridColumnData = new TxGridColumnData();
    txGridColumnData.Init(str, (TxGridColumnType) 0);
    TxGridColumnDataCollection columnDataCollection = new TxGridColumnDataCollection();
    columnDataCollection.AddItem(txGridColumnData);
    TxGridDescription txGridDescription = new TxGridDescription();
    txGridDescription.SetData(columnDataCollection, 0);
    this.m_partsTxObjGridCtrl.Init(txGridDescription);
  }

  public virtual void OnInitTxForm() => this.RegisterSimulationEvents();

  private void RegisterSimulationEvents()
  {
    TxApplication.ActiveDocument.SimulationPlayer.SimulationStartedForward += new TxSimulationPlayer_SimulationStartedForwardEventHandler(this.SimulationPlayer_SimulationStartedForward);
    TxApplication.ActiveDocument.SimulationPlayer.SimulationStartedBackward += new TxSimulationPlayer_SimulationStartedBackwardEventHandler(this.SimulationPlayer_SimulationStartedBackward);
    TxApplication.ActiveDocument.SimulationPlayer.SimulationStopped += new TxSimulationPlayer_SimulationStoppedEventHandler(this.SimulationPlayer_SimulationStopped);
    TxApplication.ActiveDocument.SimulationPlayer.SimulationEndedBackward += new TxSimulationPlayer_SimulationEndedBackwardEventHandler(this.SimulationPlayer_SimulationEndedBackward);
    TxApplication.ActiveDocument.SimulationPlayer.SimulationEndedForward += new TxSimulationPlayer_SimulationEndedForwardEventHandler(this.SimulationPlayer_SimulationEndedForward);
  }

  private void UnregisterSimulationEvents()
  {
    TxApplication.ActiveDocument.SimulationPlayer.SimulationStartedForward -= new TxSimulationPlayer_SimulationStartedForwardEventHandler(this.SimulationPlayer_SimulationStartedForward);
    TxApplication.ActiveDocument.SimulationPlayer.SimulationStartedBackward -= new TxSimulationPlayer_SimulationStartedBackwardEventHandler(this.SimulationPlayer_SimulationStartedBackward);
    TxApplication.ActiveDocument.SimulationPlayer.SimulationStopped -= new TxSimulationPlayer_SimulationStoppedEventHandler(this.SimulationPlayer_SimulationStopped);
    TxApplication.ActiveDocument.SimulationPlayer.SimulationEndedBackward -= new TxSimulationPlayer_SimulationEndedBackwardEventHandler(this.SimulationPlayer_SimulationEndedBackward);
    TxApplication.ActiveDocument.SimulationPlayer.SimulationEndedForward -= new TxSimulationPlayer_SimulationEndedForwardEventHandler(this.SimulationPlayer_SimulationEndedForward);
  }

  private void m_saveSimFileAsButton_Click(object sender, EventArgs e)
  {
    string str1 = "";
    string str2 = "";
    if (this.m_saveSimFileAsTextBox.Text != "")
    {
      try
      {
        str1 = Path.GetDirectoryName(this.m_saveSimFileAsTextBox.Text);
        str2 = Path.GetFileName(this.m_saveSimFileAsTextBox.Text);
      }
      catch (Exception ex)
      {
      }
    }
    if (str1 == "" || str2 == "")
    {
      str1 = "C:";
      str2 = "";
    }
    this.m_xmlSaveFileDialog.InitialDirectory = str1;
    this.m_xmlSaveFileDialog.FileName = str2;
    this.m_xmlSaveFileDialog.Title = "Save xml file as";
    this.m_xmlSaveFileDialog.Filter = "XML files|*.xml";
    if (this.m_xmlSaveFileDialog.ShowDialog() != DialogResult.Cancel)
      this.m_saveSimFileAsTextBox.Text = this.m_xmlSaveFileDialog.FileName;
    this.EnableButtons();
  }

  private void button3_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void m_saveJtAsButton_Click(object sender, EventArgs e)
  {
    string str1 = "";
    string str2 = "";
    if (this.m_saveJTFileAsTextBox.Text != "")
    {
      try
      {
        str1 = Path.GetDirectoryName(this.m_saveJTFileAsTextBox.Text);
        str2 = Path.GetFileName(this.m_saveJTFileAsTextBox.Text);
      }
      catch (Exception ex)
      {
      }
    }
    if (str1 == "" || str2 == "")
    {
      str1 = "C:";
      str2 = "";
    }
    this.m_jtSaveFileDialog.InitialDirectory = str1;
    this.m_jtSaveFileDialog.FileName = str2;
    this.m_jtSaveFileDialog.Title = "Save jt file as";
    this.m_jtSaveFileDialog.Filter = "JT files|*.jt";
    if (this.m_jtSaveFileDialog.ShowDialog() != DialogResult.Cancel)
      this.m_saveJTFileAsTextBox.Text = this.m_jtSaveFileDialog.FileName;
    this.EnableButtons();
  }

  private void EnableButtons()
  {
    bool flag = true;
    if (!this.m_createJtCheckBox.Checked && !this.m_createSimFileCheckBox.Checked)
    {
      flag = false;
    }
    else
    {
      if (this.m_createJtCheckBox.Checked && (this.m_partsTxObjGridCtrl.Count == 0 || this.m_saveJTFileAsTextBox.Text == ""))
        flag = false;
      if (flag && this.m_createSimFileCheckBox.Checked && (this.m_operationEditBox.Object == null || !this.m_operationEditBox.IsValid() || this.m_saveSimFileAsTextBox.Text == ""))
        flag = false;
    }
    this.m_createButton.Enabled = flag && !this.m_externalSimulationRunning;
  }

  private bool IsPathValid(string path)
  {
    bool flag = false;
    if (path != "")
    {
      try
      {
        string directoryName = Path.GetDirectoryName(path);
        if (directoryName != "")
        {
          if (Directory.Exists(directoryName))
            flag = true;
        }
      }
      catch (Exception ex)
      {
      }
    }
    return flag;
  }

  private bool IsExtensionValid(
    string path,
    CUiExportPaintFilesForm.ExportPaintFilesSection section)
  {
    bool flag = false;
    if (path != "")
    {
      try
      {
        string extension = Path.GetExtension(path);
        if (section != CUiExportPaintFilesForm.ExportPaintFilesSection.ExportJtSection || !(extension.ToLower() == ".jt"))
        {
          if (section == CUiExportPaintFilesForm.ExportPaintFilesSection.ExportXmlSection)
          {
            if (!(extension.ToLower() == ".xml"))
              goto label_6;
          }
          else
            goto label_6;
        }
        flag = true;
      }
      catch (Exception ex)
      {
      }
    }
label_6:
    return flag;
  }

  private bool ValidatePath(
    string path,
    CUiExportPaintFilesForm.ExportPaintFilesSection section)
  {
    bool flag = false;
    try
    {
      if (this.IsPathValid(path))
      {
        if (!this.IsExtensionValid(path, section))
        {
          int num = (int) TxMessageBox.Show(section != CUiExportPaintFilesForm.ExportPaintFilesSection.ExportJtSection ? this.m_resourceManager.GetString("SIM_FILE_EXPORT_WRONG_EXTENSION_ERR_MSG") : this.m_resourceManager.GetString("JT_EXPORT_WRONG_EXTENSION_ERR_MSG"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
          flag = false;
        }
        else
          flag = true;
        if (flag)
          flag = !File.Exists(path) || TxMessageBox.Show(string.Format(this.m_resourceManager.GetString("FILE_EXISTS_MSG"), (object) path), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes;
      }
      else
      {
        int num1 = (int) TxMessageBox.Show(this.m_resourceManager.GetString("INVALID_PATH_ERR_MSG"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
      if (flag)
      {
        if (!this.CanWriteFile(path))
        {
          int num2 = (int) TxMessageBox.Show(this.m_resourceManager.GetString("PERMISSION_DENIED_ERR_MSG"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
          flag = false;
        }
      }
    }
    catch (Exception ex)
    {
      flag = false;
    }
    return flag;
  }

  private bool CanWriteFile(string path)
  {
    bool flag = false;
    try
    {
      using (StreamWriter streamWriter = File.AppendText(path))
        flag = streamWriter.BaseStream.CanWrite;
      File.Delete(path);
    }
    catch
    {
      flag = false;
    }
    return flag;
  }

  private void SaveStorageData()
  {
    string str = "GeneratePaintFiles";
    TxFormSettings.StoreFormValue((Form) this, str, "SaveJtFilePath", this.m_saveJTFileAsTextBox.Text);
    TxFormSettings.StoreFormValue((Form) this, str, "SaveSimXmlFilePath", this.m_saveSimFileAsTextBox.Text);
    TxFormSettings.StoreFormValue((Form) this, str, "TimeInterval", this.m_timeIntervalEditBox.Value.ToString());
  }

  private void LoadStorageData()
  {
    string str = "GeneratePaintFiles";
    object obj1 = (object) null;
    object obj2 = (object) null;
    object obj3 = (object) null;
    TxFormSettings.RestoreFormValue((Form) this, str, "SaveJtFilePath", ref obj1);
    TxFormSettings.RestoreFormValue((Form) this, str, "SaveSimXmlFilePath", ref obj2);
    TxFormSettings.RestoreFormValue((Form) this, str, "TimeInterval", ref obj3);
    if (obj1 == null || obj2 == null || obj3 == null)
      return;
    this.m_saveJTFileAsTextBox.Text = obj1 as string;
    this.m_saveSimFileAsTextBox.Text = obj2 as string;
    this.m_timeIntervalEditBox.Value = Convert.ToDouble(obj3 as string);
  }

  private void CUiPaintSimulatorForm_FormClosing(object sender, FormClosingEventArgs e)
  {
    this.SaveStorageData();
    this.UnregisterSimulationEvents();
  }

  private void m_okButton_Click(object sender, EventArgs e)
  {
    if (this.m_createJtCheckBox.Checked && this.m_partsTxObjGridCtrl.IsValid() && ((Collection<ITxObject>) this.m_partsTxObjGridCtrl.Objects).Count > 0 && this.ValidatePath(this.m_saveJTFileAsTextBox.Text, CUiExportPaintFilesForm.ExportPaintFilesSection.ExportJtSection))
    {
      Cursor current = Cursor.Current;
      Cursor.Current = Cursors.WaitCursor;
      bool flag = this.m_app.ExportJT(this.m_partsTxObjGridCtrl.Objects, this.m_saveJTFileAsTextBox.Text);
      Cursor.Current = current;
      if (flag)
      {
        int num1 = (int) TxMessageBox.Show(this.m_resourceManager.GetString("JT_EXPORT_SUCCESS_MSG"), "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
      }
      else
      {
        int num2 = (int) TxMessageBox.Show(this.m_resourceManager.GetString("JT_EXPORT_FAILED_ERR_MSG"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
    }
    if (!this.m_createSimFileCheckBox.Checked || !(this.m_operationEditBox.Object is ITxRoboticOrderedCompoundOperation op) || !this.ValidateOperation(op) || !this.ValidatePath(this.m_saveSimFileAsTextBox.Text, CUiExportPaintFilesForm.ExportPaintFilesSection.ExportXmlSection))
      return;
    Cursor current1 = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    this.m_internalSimulationRunning = true;
    ArrayList errors = new ArrayList();
    bool simFile = this.m_app.GenerateSimFile(op, this.m_timeIntervalEditBox.Value, this.m_lineOpContextRadioButton.Checked, this.m_saveSimFileAsTextBox.Text, ref errors);
    this.m_internalSimulationRunning = false;
    Cursor.Current = current1;
    if (simFile)
    {
      if (errors.Count > 0)
      {
        string str = this.m_resourceManager.GetString("SIM_FILE_EXPORT_SIMULATION_ERRORS_LABEL");
        CUiExportPaintFilesErrorForm paintFilesErrorForm = new CUiExportPaintFilesErrorForm();
        paintFilesErrorForm.ErrorsTitle = str;
        paintFilesErrorForm.AddErrors(errors);
        int num = (int) ((Form) paintFilesErrorForm).ShowDialog();
      }
      else
      {
        int num3 = (int) TxMessageBox.Show(this.m_resourceManager.GetString("SIM_FILE_EXPORT_SUCCESS_MSG"), "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
      }
    }
    else
    {
      int num4 = (int) TxMessageBox.Show(this.m_resourceManager.GetString("SIM_FILE_EXPORT_FAILED_ERR_MSG"), "", MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  private bool ValidateOperation(ITxRoboticOrderedCompoundOperation op)
  {
    bool flag = true;
    if (((ITxObjectCollection) op).Count == 0)
    {
      int num = (int) TxMessageBox.Show(this.m_resourceManager.GetString("SIM_FILE_EXPORT_EMPTY_OPERATION"), "", MessageBoxButtons.OK, MessageBoxIcon.Hand);
      flag = false;
    }
    return flag;
  }

  private void m_createJtCheckBox_CheckedChanged(object sender, EventArgs e)
  {
    this.EnableCreateJtSection(this.m_createJtCheckBox.Checked);
    this.EnableButtons();
    if (!this.m_createJtCheckBox.Checked)
      return;
    this.m_partsTxObjGridCtrl.Focus();
  }

  private void m_createSimFileCheckBox_CheckedChanged(object sender, EventArgs e)
  {
    this.EnableCreateSimFileSection(this.m_createSimFileCheckBox.Checked);
    this.EnableButtons();
    if (!this.m_createSimFileCheckBox.Checked)
      return;
    this.m_operationEditBox.Focus();
  }

  private void EnableCreateJtSection(bool enable)
  {
    ((Control) this.m_partsTxObjGridCtrl).Enabled = enable;
    this.m_saveJTFileAsTextBox.Enabled = enable;
    this.m_saveJtAsButton.Enabled = enable;
  }

  private void EnableCreateSimFileSection(bool enable)
  {
    this.m_operationEditBox.Enabled = enable;
    this.m_timeIntervalEditBox.Enabled = enable;
    this.m_saveSimFileAsTextBox.Enabled = enable;
    this.m_saveSimFileAsButton.Enabled = enable;
    this.m_independentRadioButton.Enabled = enable;
    this.m_lineOpContextRadioButton.Enabled = enable;
  }

  private void m_partsTxObjGridCtrl_RowDeleted(
    object sender,
    TxObjGridCtrl_RowDeletedEventArgs args)
  {
    this.EnableButtons();
  }

  private void m_partsTxObjGridCtrl_Picked(object sender, TxObjGridCtrl_PickedEventArgs args)
  {
    ITxObject compound = args.Obj;
    if (!(compound is ITxComponent))
    {
      ITxComponent parentComponent = this.GetParentComponent(compound);
      if (parentComponent != null)
        this.m_partsTxObjGridCtrl.AppendObject((ITxObject) parentComponent);
      if (compound is ITxObjectCollection)
      {
        TxObjectList childComponents = this.GetChildComponents(compound as ITxObjectCollection);
        if (childComponents != null)
        {
          foreach (ITxObject itxObject in (Collection<ITxObject>) childComponents)
            this.m_partsTxObjGridCtrl.AppendObject(itxObject);
        }
      }
    }
    this.EnableButtons();
  }

  private TxObjectList GetChildComponents(ITxObjectCollection compound)
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter(typeof (ITxComponent));
    return compound.GetAllDescendants((ITxTypeFilter) txTypeFilter);
  }

  private ITxComponent GetParentComponent(ITxObject obj)
  {
    ITxObject parentComponent = obj;
    while (!(parentComponent is ITxComponent) && parentComponent.Collection != null)
      parentComponent = (ITxObject) parentComponent.Collection;
    return parentComponent as ITxComponent;
  }

  private void m_operationEditBox_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    this.EnableButtons();
  }

  private void m_operationEditBox_TypeValid(object sender, EventArgs e) => this.EnableButtons();

  private void m_saveSimFileAsTextBox_TextChanged(object sender, EventArgs e)
  {
    this.EnableButtons();
  }

  private void m_saveJTFileAsTextBox_TextChanged(object sender, EventArgs e)
  {
    this.EnableButtons();
  }

  public void SetPickProviders()
  {
    // ISSUE: unable to decompile the method.
  }

  private void SimulationPlayer_SimulationEndedForward(
    object sender,
    TxSimulationPlayer_SimulationEndedForwardEventArgs args)
  {
    if (this.m_internalSimulationRunning)
      return;
    this.m_externalSimulationRunning = false;
    this.EnableButtons();
  }

  private void SimulationPlayer_SimulationEndedBackward(
    object sender,
    TxSimulationPlayer_SimulationEndedBackwardEventArgs args)
  {
    if (this.m_internalSimulationRunning)
      return;
    this.m_externalSimulationRunning = false;
    this.EnableButtons();
  }

  private void SimulationPlayer_SimulationStopped(
    object sender,
    TxSimulationPlayer_SimulationStoppedEventArgs args)
  {
    if (this.m_internalSimulationRunning)
      return;
    this.m_externalSimulationRunning = false;
    this.EnableButtons();
  }

  private void SimulationPlayer_SimulationStartedBackward(
    object sender,
    TxSimulationPlayer_SimulationStartedBackwardEventArgs args)
  {
    if (this.m_internalSimulationRunning)
      return;
    this.m_externalSimulationRunning = true;
    this.EnableButtons();
  }

  private void SimulationPlayer_SimulationStartedForward(
    object sender,
    TxSimulationPlayer_SimulationStartedForwardEventArgs args)
  {
    if (this.m_internalSimulationRunning)
      return;
    this.m_externalSimulationRunning = true;
    this.EnableButtons();
  }

  private void m_operationEditBox_Enter(object sender, EventArgs e)
  {
    this.m_operationEditBox.ListenToPick = true;
  }

  private void m_operationEditBox_Leave(object sender, EventArgs e)
  {
    this.m_operationEditBox.ListenToPick = false;
  }

  private enum ExportPaintFilesSection
  {
    ExportJtSection,
    ExportXmlSection,
  }
}
